let app = getApp();
Component({
  properties: {
    notload: {
      type:Boolean,
      value:false
    }
  },
  data: {
    needLogin: false,
  },
  lifetimes: {
    attached: function () {
      wx.getUserInfo({
        //已授权用户信息
        success: res => {
          this.setData({
            needLogin: false
          })
        },
        //未授权用户信息
        fail: err => {
          this.setData({
            needLogin: true
          })
        }
      })
    }
  },
  methods: {
    /**
     * 授权登录
     */
    authorLogin: function (e) {
      app.login(() => {    
        if (!this.data.notload) {
          wx.reLaunch({
            url: '/pages/index/index'
          })
        } else {
            this.setData({ needLogin: false }
          );
        }
      }, () => {
        this.setData({
          needLogin: false
        })
      })
    }
  }
})